package com.yuhang.demo;

import com.PayReqDetail;
import com.alibaba.fastjson.JSONArray;
import com.go2.shipping.common.encrypt.AES;
import com.yuhang.demo.util.PostUtil;
import com.yuhang.demo.vo.pay.PayType;
import com.yuhang.demo.vo.pay.TradeType;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PayTest {

    static String api = "http://127.0.0.1:29010/";

    public static final String APP_AES_KEY = "2016.01_go2plus_chengdu_china";
    static AES aes = new AES(APP_AES_KEY);
    static String url = api + "comm/gpay";

    public static void main(String[] args) throws Exception {

        //充值
//        String ret = deposit();
        //订单支付
//        String ret = orderPay();
        //货款到账
        String ret = orderIn();
        System.out.println(ret);
    }
    public static String orderIn() throws Exception {
        Map<String, Object> formparams = new HashMap<String, Object>();
        formparams.put("balanceAmount", new BigDecimal("0.01"));
        formparams.put("onlineAmount",BigDecimal.ZERO );
        formparams.put("remark", "test");
        formparams.put("tradeType", TradeType.ORDERIN);
        formparams.put("payType", PayType.BALANCE);
        formparams.put("userId", 59722L);
        formparams.put("gsbId", 55934L);
        formparams.put("body", "充值");
        formparams.put("subject", "充值");
        formparams.put("username", "dpc0827");
        formparams.put("tradeNo", "gsyh_199912");
        formparams.put("returnUrl", "http://baidu.com");
        formparams.put("payPlatform", "gsb");
        formparams.put("payword", aes.encrypt("123456"));
        PayReqDetail rrd = new PayReqDetail();
        rrd.setAmount(new BigDecimal("0.01"));
        rrd.setDataId(5L);
        rrd.setDataNo("2");
        rrd.setGsbId(55934L);
        rrd.setUserId(59722L);
        rrd.setUsername("dpc0827");
        List<PayReqDetail> list = new ArrayList<PayReqDetail>();
        list.add(rrd);
        formparams.put("data", JSONArray.toJSONString(list));
        return PostUtil.httpAppPay(url, formparams);
    }
    /**
     * 订单支付
     * @return
     * @throws Exception
     */
    public static String orderPay() throws Exception {
        Map<String, Object> formparams = new HashMap<String, Object>();
        formparams.put("balanceAmount", BigDecimal.ZERO);
        formparams.put("onlineAmount", new BigDecimal("0.01"));
        formparams.put("remark", "test");
        formparams.put("tradeType", TradeType.ORDERPAY);
        formparams.put("payType", PayType.ALIPAY);
        formparams.put("userId", 59722L);
        formparams.put("gsbId", 55934L);
        formparams.put("body", "充值");
        formparams.put("subject", "充值");
        formparams.put("username", "dpc0827");
        formparams.put("tradeNo", "gsyh_199912");
        formparams.put("returnUrl", "http://baidu.com");
        formparams.put("payPlatform", "gsb");
        formparams.put("payword", aes.encrypt("123456"));
        PayReqDetail rrd = new PayReqDetail();
        rrd.setAmount(new BigDecimal("0.01"));
        rrd.setDataId(4L);
        rrd.setDataNo("2");
        rrd.setGsbId(59722L);
        rrd.setUserId(55934L);
        rrd.setUsername("dpc0827");
        List<PayReqDetail> list = new ArrayList<PayReqDetail>();
        list.add(rrd);
        formparams.put("data", JSONArray.toJSONString(list));
        return PostUtil.httpAppPay(url, formparams);
    }

    /**
     * 充值
     * @return
     * @throws Exception
     */
    public static String deposit() throws Exception {
        Map<String, Object> formparams = new HashMap<String, Object>();
        formparams.put("balanceAmount", BigDecimal.ZERO);
        formparams.put("onlineAmount", new BigDecimal("0.01"));
        formparams.put("remark", "test");
        formparams.put("tradeType", TradeType.DEPOSIT);
        formparams.put("payType", PayType.ALIPAY);
        formparams.put("userId", 55934L);
        formparams.put("gsbId", 59722L);
        formparams.put("body", "充值");
        formparams.put("subject", "充值");
        formparams.put("username", "dpc0827");
        formparams.put("tradeNo", "gsyh_199912");
        formparams.put("returnUrl", "http://baidu.com");
        formparams.put("payPlatform", "gsb");
        PayReqDetail rrd = new PayReqDetail();
        rrd.setAmount(new BigDecimal("0.01"));
        rrd.setDataId(2L);
        rrd.setDataNo("2");
        rrd.setGsbId(55934L);
        rrd.setUserId(59722L);
        rrd.setUsername("dpc0827");
        List<PayReqDetail> list = new ArrayList<PayReqDetail>();
        list.add(rrd);
        formparams.put("data", JSONArray.toJSONString(list));
        return PostUtil.httpAppPay(url, formparams);
    }
}
